<?php

namespace app\common\business\problem;

use app\common\business\BaseBus;
use app\common\model\Problem;

class ProblemBus extends BaseBus
{
    public static function getLists($type=0)
    {
        switch ($type) {
            case 1:
                $field = 'id,title,level_type,created_at';
                break;
            case 2:
                $field = 'id,title,created_at';
                break;
            default:
                $field = 'id,title,level_type';
                break;
        }
        $res = Problem::field($field);
        if (in_array($type, [1,2])) {
            $res->where('type', $type)->append(['level_name']);
        }
        if ($type == 2) {
            $res->with(['answer' => function($answer) {
                $answer->field('id,pid,title');
            }]);
        }
        return $res->select();
    }
}
